package com.eastedu.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.eastedu.common.util.SchoolGroupMappingUtil;
import com.eastedu.repository.assignment.mapper.AssignmentMapper;
import com.eastedu.repository.assignment.po.AssignmentPO;
import com.eastedu.service.AbstractDataSyncService;
import com.eastedu.service.DataSourceService;
import org.springframework.stereotype.Service;


/**
 * 〈〉
 *
 * @author ZHISHUAI.ZHANG
 * @since 2021/7/28
 */
@Service("assignment-source")
@DS("assignment")
public class AssignmentDataSourceServiceImpl extends AbstractDataSyncService<AssignmentPO> implements DataSourceService {

    public AssignmentDataSourceServiceImpl(AssignmentMapper mapper) {
        super(mapper);
        /// super.addScriptByTableName("t_assignment_resource");
        super.addScript("UPDATE t_assignment_resource t1 SET t1.sync_state = 0 \n" +
                "WHERE school_group_id IS NULL OR school_group_id = 0");
    }

    @Override
    protected void updateContent(AssignmentPO po) {
        po.setSchoolGroupId(SchoolGroupMappingUtil.mappingId(po.getOwnerOrganizationId()));
    }

}